<?php
/**
 * 恢复被删除的表
 * 运行此脚本可以恢复所有被删除的表
 */

$host = '101.35.252.112';
$port = '45508';
$dbname = 'trace';
$username = 'root';
$password = 'CeyZFHxjPABhp2Hz';

try {
    $pdo = new PDO("mysql:host=$host;port=$port;dbname=$dbname;charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    echo "✅ 数据库连接成功\n";
    
    // 读取并执行所有结构文件
    $structureFiles = glob(__DIR__ . '/*_structure.sql');
    foreach ($structureFiles as $file) {
        $sql = file_get_contents($file);
        $pdo->exec($sql);
        echo "✅ 恢复表结构: " . basename($file) . "\n";
    }
    
    // 读取并执行所有数据文件
    $dataFiles = glob(__DIR__ . '/*_data.sql');
    foreach ($dataFiles as $file) {
        $sql = file_get_contents($file);
        $pdo->exec($sql);
        echo "✅ 恢复表数据: " . basename($file) . "\n";
    }
    
    echo "\n🎉 所有表已恢复完成！\n";
    
} catch (PDOException $e) {
    echo "❌ 恢复失败: " . $e->getMessage() . "\n";
    exit(1);
}
